package part01_七大原则.p03_依赖倒转原则.依赖关系传递的三种方式;

/**
 * @ClassName: DependencyPass02
 * @Author: AllenSun
 * @Date: 2019/12/2 23:59
 */
public class DependencyPass02 {
    public static void main(String[] args) {
        HaiEr haiEr = new HaiEr();
        //初始化的时候直接传入
        OpenAndClose02 openAndClose02 = new OpenAndClose02(haiEr);
        openAndClose02.open();
    }
}

//通过构造方法依赖传递
interface IOpenAndClose02{
    public void open();
}

interface ITV02{
    public void play();
}

class OpenAndClose02 implements IOpenAndClose02{
    public ITV02 tv;
    public OpenAndClose02(ITV02 tv){
        this.tv=tv;
    }

    @Override
    public void open() {
        this.tv.play();
    }
}

class HaiEr implements ITV02{
    @Override
    public void play() {
        System.out.println("海尔电视机，打开");
    }
}